<template>
  <a-card :bordered="false">

    <!-- 左侧面板 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="8" :sm="8">
            <a-form-item label="壁纸类型" :label-col="{span: 6}" :wrapper-col="{span: 14, offset: 1}">
              <ants-dict-select-tag
                v-model="queryParam.fileType"
                type="select"
                :trigger-change="true"
                dict-code="wallpaper_type"
                placeholder="请选择壁纸类型"
              />
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>

      <div class="table-operator" style="border-top: 5px">
        <a-button type="primary" icon="plus" @click="handleAdd">添加</a-button>
      </div>

      <a-table
        ref="table"
        row-key="id"
        size="middle"
        bordered
        :columns="columns"
        :data-source="dataSource"
        :pagination="pagination"
        :loading="loading"
        @change="handleTableChange"
        class="j-table-force-nowrap"
      >
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"
            @click="handlePreview(text)"
          >
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>

    </div>
    <wallpaper-modal ref="modalForm" @ok="modalFormOk"/>  <!-- 字典类型 -->
    <a-modal :visible="previewVisible" :footer="null" @cancel="handleImgCancel()">
      <img alt="example" style="width: 100%" :src="previewImage">
    </a-modal>
  </a-card>
</template>

<script>
import { TableListMixin } from '@/mixins/TableListMixin'
import WallpaperModal from './modules/WallpaperModal'
import AntsDictSelectTag from '@/components/dict/AntsDictSelectTag'

export default {
  name: 'Wallpaper',
  components: {
    WallpaperModal,
    AntsDictSelectTag
  },
  mixins: [TableListMixin],
  data() {
    return {
      description: '这是数据字典页面',
      visible: false,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '壁纸类型',
          align: 'center',
          dataIndex: 'fileType_dictText'
        },
        {
          title: '壁纸',
          align: 'center',
          dataIndex: 'fileName',
          scopedSlots: { customRender: 'imgSlot' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 100,
          scopedSlots: { customRender: 'action' }
        }
      ],
      labelCol: {
        xs: { span: 8 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 16 },
        sm: { span: 19 }
      },
      url: {
        list: '/wallpaper/list',
        delete: '/wallpaper/delete'
      }
    }
  },
  computed: {},
  methods: {
  }
}
</script>
